package top.appx.service.impl;

import org.springframework.stereotype.Service;
import top.appx.dao.UserDao;
import top.appx.entity.UserEntity;
import top.appx.service.UserService;
import top.appx.vo.Pager;
import top.appx.vo.UserVO;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by zwy on 2015-5-20.
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserDao userDao;
    public Pager<UserVO> queryByPage(UserEntity bean, int page, int rows) {
        Pager<UserEntity> pager = userDao.queryByPage(bean,page,rows);
        Pager<UserVO> pagerVO = new Pager<UserVO>();
        List<UserVO>  list = new ArrayList<UserVO>();
        for(UserEntity u:pager.getRows()){
            UserVO uv = new UserVO(u);
            list.add(uv);
        }
        pagerVO.setTotal(pager.getTotal());
        pagerVO.setRows(list);
        return pagerVO;
    }

    public void save(UserEntity entity) {
        userDao.save(entity);
    }

    public void delete(UserEntity entity) {
        entity = userDao.getById(UserEntity.class,entity.getId());
        userDao.delete(entity);
    }
}
